import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class Demo1 {
    /*public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor()
    }*/
    public static void main(String[] args) {
        //ExecutorService executorService = Executors.newCachedThreadPool();//自动扩容
        ExecutorService service = Executors.newFixedThreadPool(4);//不扩容
        for (int i = 0; i < 1000; i++) {
            final int n = i;
            service.submit(() -> {
                System.out.println(Thread.currentThread().getName()+ "," + n);
            });
        }

        /*for (int i = 0; i < 1000; i++) {
            // 此处的 id 不需要修改, 是 "事实 final"
            final int id = i;
            service.submit(new Runnable() {
                @Override
                public void run() {
                    String name = Thread.currentThread().getName();
                    System.out.println("hello " + name + ", " + id);
                }
            });
        }*/
    }
}
